extern crate encoding;
use std::net::UdpSocket;
use std::{io};
use encoding::{DecoderTrap,EncoderTrap, Encoding};
use encoding::all::UTF_8;

fn main() -> std::io::Result<()> {
    let socket = UdpSocket::bind("127.0.0.1:8000")?;
        socket.connect("127.0.0.1:8080")?;
    loop {
        let mut input = String::new();
        io::stdin().read_line(&mut input)?;
        let input = UTF_8.encode(&input,EncoderTrap::Strict).unwrap();
        socket.send(input.as_slice())?;
        let mut buffer = [0u8; 1500];
        socket.recv_from(&mut buffer)?;
        println!("recv: {}",UTF_8.decode(&buffer,DecoderTrap::Ignore).expect("Could not write buffer as string"));
    }

}

